﻿namespace Awsc.DataAcquisitionSys.Core.Databases
{
    public interface ISentinelRepository
    {
        Task CreateSentinelTableAsync(string tableName);
    }
    public class SentinelRepository : ISentinelRepository
    {
        private readonly SQLiteHelper sqliteHelper;

        public SentinelRepository(SQLiteHelper sqliteHelper)
        {
            this.sqliteHelper = sqliteHelper;
        }
        public async Task CreateSentinelTableAsync(string tableName)
        {
            using var cmd = sqliteHelper.Connection.CreateCommand();

            // 创建任务元数据表
            var sql = @$"
            CREATE TABLE IF NOT EXISTS {tableName} (
                ID INTEGER PRIMARY KEY AUTOINCREMENT,
                MissionName TEXT NOT NULL,
                CreateTime REAL,
                FinishTime REAL,
                ManagerName TEXT,
                TeamID TEXT,
                Unit TEXT,
                Location TEXT,
                ConstructionLocation TEXT,
                WellDeep TEXT,
                ManulBottomHole TEXT,
                FillTime REAL,
                WellMode TEXT,
                WellType TEXT,
                DesignLayer TEXT,
                CurrentLayer TEXT,
                WorkType TEXT,
                DeviceMode TEXT,
                WorkingProcedure TEXT,
                WellParkerMode TEXT,
                BopConfiguration TEXT,
                LatestPresureTest TEXT,
                LatestPresureTestTime REAL,
                Remarks TEXT
            );
            
            PRAGMA journal_mode = WAL;
            PRAGMA synchronous = NORMAL;
            PRAGMA cache_size = -10000; -- 10MB cache
            PRAGMA temp_store = MEMORY;
            PRAGMA busy_timeout = 3000;";
            this.sqliteHelper.CreateTableAsync(sql).ConfigureAwait(false).GetAwaiter().GetResult();
        }

 
    }
}
